import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.swt.widgets.Button;


public class friendlist {

	protected Shell shell;
	private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());

	/**
	 * Launch the application.
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			friendlist window = new friendlist();
			window.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Open the window.
	 */
	public void open() {
		Display display = Display.getDefault();
		createContents();
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

	/**
	 * Create contents of the window.
	 */
	protected void createContents() {
		shell = new Shell();
		shell.setSize(330, 540);
		shell.setText("SWT Application");
		
		Label lblCurrentUserName = new Label(shell, SWT.NONE);
		lblCurrentUserName.setBounds(10, 10, 87, 17);
		lblCurrentUserName.setText("Logged in as:");
		
		Label lblFriends = new Label(shell, SWT.NONE);
		lblFriends.setBounds(10, 33, 155, 17);
		lblFriends.setText("Friends");
		
		Label lblStatus = new Label(shell, SWT.NONE);
		lblStatus.setBounds(248, 33, 70, 17);
		lblStatus.setText("Status");
		
		List list = new List(shell, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL);
		list.setBounds(10, 56, 308, 392);
		// use list.add(item) to add items
		list.add("AAA\t\t\t\t\t\t\t\t\tonline");
		list.add("BBB\t\t\t\t\t\t\t\t\tonline");
		list.add("CCC\t\t\t\t\t\t\t\t\toffline");
		list.add("DDD\t\t\t\t\t\t\t\t\toffline");
		
		Menu menu = new Menu(shell, SWT.BAR);
		shell.setMenuBar(menu);
		
		MenuItem mntmNewSubmenu = new MenuItem(menu, SWT.CASCADE);
		mntmNewSubmenu.setText("File");
		
		Menu menu_1 = new Menu(mntmNewSubmenu);
		mntmNewSubmenu.setMenu(menu_1);
		
		MenuItem mntmLogOut = new MenuItem(menu_1, SWT.NONE);
		mntmLogOut.setText("Log Out");
		mntmLogOut.addListener(SWT.Selection, new Listener() {
			public void handleEvent(org.eclipse.swt.widgets.Event event) {
				// log out
				shell.close();
				new login().open();
			}
		});
		
		MenuItem mntmExit = new MenuItem(menu_1, SWT.NONE);
		mntmExit.setText("Exit");
		mntmExit.addListener(SWT.Selection, new Listener() {
			public void handleEvent(org.eclipse.swt.widgets.Event event) {
				System.exit(0);
			}
		});
		
		MenuItem mntmFriends = new MenuItem(menu, SWT.CASCADE);
		mntmFriends.setText("Friends");
		
		Menu menu_2 = new Menu(mntmFriends);
		mntmFriends.setMenu(menu_2);
		
		MenuItem mntmAddFriend = new MenuItem(menu_2, SWT.NONE);
		mntmAddFriend.setText("Add Friend");
		mntmAddFriend.addListener(SWT.Selection, new Listener() {
			public void handleEvent(org.eclipse.swt.widgets.Event event) {
				new addfriend(Display.getCurrent().getActiveShell(), 0).open();
			}
		});
		
		MenuItem mntmRemoveFriend = new MenuItem(menu_2, SWT.NONE);
		mntmRemoveFriend.setText("Remove Friend");
		mntmRemoveFriend.addListener(SWT.Selection, new Listener() {
			public void handleEvent(org.eclipse.swt.widgets.Event event) {
				new removefriend(Display.getCurrent().getActiveShell(), 0).open();
			}
		});
		
		MenuItem mntmSettings = new MenuItem(menu, SWT.CASCADE);
		mntmSettings.setText("Settings");
		
		Menu menu_3 = new Menu(mntmSettings);
		mntmSettings.setMenu(menu_3);
		
		MenuItem mntmChangePassword = new MenuItem(menu_3, SWT.NONE);
		mntmChangePassword.setText("Change Password");
		mntmChangePassword.addListener(SWT.Selection, new Listener() {
			public void handleEvent(org.eclipse.swt.widgets.Event event) {
				new changepassword(Display.getCurrent().getActiveShell(), 0).open();
			}
		});
		
		Label lblUserNamePlace = new Label(shell, SWT.NONE);
		lblUserNamePlace.setBounds(103, 10, 215, 17);
		lblUserNamePlace.setText("User Name Place Holder");
		
		Button btnChat = new Button(shell, SWT.NONE);
		btnChat.setBounds(227, 454, 91, 29);
		formToolkit.adapt(btnChat, true, true);
		btnChat.setText("Chat");
		btnChat.addListener(SWT.Selection, new Listener() {
			public void handleEvent(org.eclipse.swt.widgets.Event event) {
				new chatwindow().open();
			}
		});

	}
}
